package com.ykh.spring.pojo.service.impl;
import com.ykh.spring.pojo.service.CheckoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-08-26
 * Time: 9:24
 */
@Service
public class CheckOutServiceImpl implements CheckoutService {
    @Autowired
    private BookServiceImpl bookService;

    //一次购买多本图书
    @Override
    @Transactional(
            propagation = Propagation.REQUIRES_NEW
    )
    public void checkOut(Integer[] bookIds, Integer userId) {
        for (Integer bookId : bookIds) {
            bookService.buyBook(bookId, userId);
        }
    }
}
